import os
from pymud import IConfig, Session


class MyConfig(IConfig):
    def __init__(self, session: Session, *args, **kwargs):
        # 是否调用 #reload 命令重新加载模块
        reload = kwargs.get("reload", False)

        self.session = session
        self.session.info(session)
        self.session.info(self.session.getVariable("charname"))
        mods = list()

        mods.append("script.公共触发")
        mods.append("script.GMCP_channel")

        # cur_dir = os.path.dirname(__file__)
        # root_dir = os.path.join(cur_dir, "pymud")

        # dir = os.path.join(root_dir, "script")
        # if os.path.exists(dir):
        #     for file in os.listdir(dir):
        #         if file.endswith(".py") and (not file.startswith("__")):
        #             mods.append(f"pymud.script.{file[:-3]}")

        # dir = os.path.join(root_dir, "jobs")
        # if os.path.exists(dir):
        #     for file in os.listdir(dir):
        #         if file.endswith(".py") and (not file.startswith("__")) and (file != "jobManager.py") and (file != "job.py"):
        #             mods.append(f"pymud.jobs.{file[:-3]}")

        session.load_module(mods)

        if reload:
            session.reload_module(mods)

        self.mods = mods

    def __unload__(self):
        self.session.unload_module(self.mods)
